package com.jlect.swebing.ui.client;

/**
 * Stores component's shape
 *
 * @author Sergey Kozmin
 * @since 10.11.2007 22:50:35
 */
public class Rectangle {
    private int x;
    private int y;
    private int width;
    private int height;

    public Rectangle(int x, int y, int width, int height) {
        setBounds(x, y, width, height);
    }

    public void setLocation(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void setBounds(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        setWidth(width);
        setHeight(height);
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setWidth(int width) {
        if(width < 0) {
            throw new IllegalArgumentException("Width could not be less than 0. ");
        }
        this.width = width;
    }

    public void setHeight(int height) {
        if(height < 0) {
            throw new IllegalArgumentException("Height could not be less than 0. ");
        }
        this.height = height;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public Location getLocation() {
        return new Location(x, y);//todo optimize
    }

    public Dimension getSize() {
        return new Dimension(width, height);//todo optimize
    }

    public String toString() {
        return "Rectangle{" +
                "x=" + x +
                ", y=" + y +
                ", width=" + width +
                ", height=" + height +
                '}';
    }
}
